package day03;

import java.util.Scanner;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/9
 */
public class GoldbachConjecture {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            System.out.print("请输入一个不小于6的偶数(输入0退出)：");
            int input = sc.nextInt();

            if (input == 0) {
                System.out.println("已退出输入！");
                break;
            }

            if (input < 6 || input % 2 != 0) {
                System.out.println("输入不合法！");
                continue; // 重新输入
            }

            boolean found = false; // 检查是否找到奇素数对
            for (int i = 3; i < input / 2; i+=2) {
                if (isPrime(i) && isPrime(input - i)) {
                    System.out.println(input + " = " + i + " + " + (input - i));
                    found = true;
                }
            }

            if (!found) {
                System.out.println("未找到符合条件的素数对！");
            }

        }
    }

    // 检查一个数是否是素数
    public static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }
        if (num == 2) {
            return true;
        }
        if (num % 2 == 0) {
            return false;
        }
        for (int i = 3; i * i <= num; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
}
